package com.meitianhui.convenitenbuy.module.order.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jakewharton.rxbinding.view.RxView;
import com.meitianhui.convenitenbuy.R;
import com.meitianhui.convenitenbuy.module.order.model.bean.OrderInfo;
import com.meitianhui.convenitenbuy.util.GlideUtils;

import java.util.List;
import java.util.Map;

/**
 * 积分兑（Bonus Points Payment）订单页面 adapter.
 * Created by Liam on 2018/3/17.
 */

public class BPPOrderAdapter extends BaseQuickAdapter<OrderInfo.ListBean, BaseViewHolder> {

    private Context mContext;
    private Map<String, String> mUrlMap;

    public BPPOrderAdapter(Context context,
                           @Nullable List<OrderInfo.ListBean> data,
                           Map<String, String> urlMap) {
        super(R.layout.item_order_bonus_points_payment, data);
        mContext = context;
        mUrlMap = urlMap;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderInfo.ListBean item) {

        RecyclerView recyclerView = helper.getView(R.id.rv_bpp_order_list);
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        recyclerView.setLayoutManager(layoutManager);
        RxView.visibility(helper.getView(R.id.rv_bpp_order_list)).call(true);
        RxView.visibility(helper.getView(R.id.ll_bpp_shop)).call(true);

        helper.setText(R.id.tv_bpp_good_name, item.getGoods_title());
        helper.setText(R.id.tv_bpp_good_price, "¥ " + item.getAmount());

        helper.setText(R.id.tv_order_number, item.getOrder_no());
        helper.setText(R.id.tv_create_date, item.getOrder_date());
        helper.setText(R.id.tv_order_pay_type, "积分");
        helper.setText(R.id.tv_phone, item.getMember_mobile());
        helper.setText(R.id.tv_address, item.getDelivery_address());

        String pathID = item.getPath_id();
        String url = mUrlMap.get(pathID);
        GlideUtils.setRectImage(mContext, url, R.mipmap.wallet_coupon_item_default,
                R.mipmap.wallet_coupon_item_default, helper.getView(R.id.iv_bpp_good));
    }

    public void setNewData(List data, Map<String, String> map) {
        setNewData(data);
        this.mUrlMap = map;
    }

    public void addData(List data, Map<String, String> map) {
        addData(data);
        mUrlMap.putAll(map);
    }

}
